package com.boss.core.manage;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;
import hudson.Extension;
import hudson.model.ComputerSet;

/**
 * Boss Prperty for Environment Variable
 * DO NOT USE - still incomplete
 * @author Momin Noor Khan
 */
public class BossEnvVarProperty extends BossProperty {
    //private Entry entry;
    private String value;

    @DataBoundConstructor
    public BossEnvVarProperty(String name, String value) {
        super(name, null);
        this.value = value;
        //this.entry = new Entry(name,value);
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

//	public Entry getEntry()
//    {
//    	return entry;
//    }


    //@Extension  - commented out for the time being
    public static class DescriptorImpl extends BossPropertyDescriptor {
        @Override
        public String getDisplayName() {
            return "Environment Variable";
        }

        public String getHelpPage() {
            // yes, I know this is a hack.
            ComputerSet object = Stapler.getCurrentRequest().findAncestorObject(ComputerSet.class);
            if (object != null) {
                // we're on a node configuration page, show show that help page
                return "/help/system-config/nodeEnvironmentVariables.html";
            } else {
                // show the help for the global config page
                return "/help/system-config/globalEnvironmentVariables.html";
            }
        }

        @Override
        public BossProperty newInstance(BossConfiguration configuration) {
            return null;
        }
    }

    public static class Entry {
        private String key;
        private String value;

        @DataBoundConstructor
        public Entry(String key, String value) {
            this.key = key;
            this.value = value;
        }

        public String getKey() {
            return key;
        }

        public String getValue() {
            return value;
        }
    }

}
